import { NCarouselItem } from "naive-ui";

import { getSlotsDom } from "../utils";
import type { BaseComponentType } from "../types";
import type { HTMLAttributes } from "vue";
export type CarouselItemFactoryConstructorType = {
  defaultSlot: BaseComponentType;
  attrs: HTMLAttributes;
};
export class CarouselItemFactory {
  private defaultSlot: BaseComponentType = null;
  private attrs: HTMLAttributes = {};

  constructor(data?: CarouselItemFactoryConstructorType) {
    if (data?.attrs) this.setAttrs(data.attrs);
    if (data?.defaultSlot) this.setDefault(data.defaultSlot);
  }

  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this;
  }

  setDefault(component: BaseComponentType) {
    this.defaultSlot = component;
    return this;
  }

  create() {
    return (
      <NCarouselItem {...this.attrs}>
        {{
          default: () => getSlotsDom(this.defaultSlot),
        }}
      </NCarouselItem>
    );
  }
}
